package com.snopy.stream;

import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @author snopy
 * @version 1.0.0
 * @classname DemoDataStream
 * @description problems feedback acronym
 * @email 77912204@qq.com
 * @date 2022/07/29 15:59
 */
@Slf4j
public class DemoDataStream {
    /*
    * 应用层
    * 表示层
    * 会话层
    * 传输层
    * 网络层
    * 数据链路层
    * 物理层
    *  transport
    * */
    public static void main(String[] args) {
        DataInputStream inputStream = null;
        DataOutputStream outputStream = null;
        try {
            inputStream = new DataInputStream(Files.newInputStream(Paths.get("Sonata_java8/src/main/resources/xanadu.txt")));
            outputStream = new DataOutputStream(Files.newOutputStream(Paths.get("Sonata_java8/src/main/resources" +
                    "/datastreamoutput" +
                    ".txt")));
            int c;
            while((c=inputStream.read())!=-1){
                outputStream.write(c);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if (inputStream!=null){
                try {
                    inputStream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (outputStream!=null){
                try {
                    outputStream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
